<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Db;
use think\Model;
class Club extends Common
{
	public function index(){

    /*$clubcourses=Db::name("clubcourses")->select();
    $this->assign("clubcourses",$clubcourses);

    $clubvideos=Db::name("clubvideos")->select();
    $this->assign("clubvideos",$clubvideos);*/
	

    /*var_dump($clubs);
    exit();*/
    $clubs=Db::name("clubs")->select();
    $this->assign("clubs",$clubs);
    return $this->fetch();
    /*"select * from clubs a inner join clubvideos v on a.c_id=v.cv_id join clubcourses t on a.c_id=t.cc_id"
    'select c.c_id,c_name,c_intro,c_address,c_tel, ca_name , count(cc.*) as coursecount , count(cv.*) as videocount from clubs c join clubadmins ca on c.c_id=ca.c_id join clubcourses cc on c.c_id=cc.c_id join clubvideos cv on c.c_id=cv.c_id'*/
  }

  public function jiekou(){
  $rs=db('clubs')->select();
  return json($rs);
}

 public function add(){
    if (request()->isPost()) {
     //创建数组，给video表的所有字段赋值
      $data=[
       'c_name'=>input('param.c_name'),
        'c_address'=>input('param.c_address'),
       /*'cc_id'=>input('param.cc_name'),
       'cv_id'=>input('param.cv_name'),*/
        'c_tel'=>input('param.c_tel'),
        'c_intro'=>input('param.c_intro'),
      ];
      //存入数据库
    $res=Db::name("clubs")->insert($data);
    //处理结果
    if ($res) {
      $this->success("添加成功");
    }else{
      $this->error("添加失败");
    }
    }
  }


  public function edit(){
    $c_id=input('c_id');
    $clubs=Db::name("clubs")->find($c_id);
    echo json_encode($clubs);
  }
  public function update(){
      $data=[
        'c_name'=>input('param.c_name'),
        'c_address'=>input('param.c_address'),
       /*'cc_id'=>input('param.cc_name'),
       'cv_id'=>input('param.cv_name'),*/
        'c_tel'=>input('param.c_tel'),
        'c_intro'=>input('param.c_intro'),
      ];
$c_id=input('param.c_id');
var_dump($data);
//修改数表
      if(Db::name('clubs')->where("c_id",$c_id)->update($data)){
        $this->success('修改成功');
      }else{
        $this->error('修改失败');
      }
    }

public function delete($id){

    if (Db::name("clubs")->delete($id)) {
      $this->success('删除成功');
    }else $this->error('删除失败');
  }



 
}
